<template>
  <div>
    <!-- 标题-->
    <div>
      <a-page-header title="课程组列表" />
    </div>
    <!--下面的div包括下拉框，搜索框，按钮等控件-->
    <div>
      <a-form layout="inline" :form="form" :labelCol="{
        md:{span:6},
        xs:{span:12}
      }" :wrapperCol="{
        md:{span:5},
        xs:{span:12}
      }">
        <a-form-item label="所属课程" >
          <a-select
              placeholder="请选择课程"
              @focus="getCourses"
              v-model="selectCourse"
              style="width: 200px"
              :allowClear="true"
          >
            <a-select-option :value="i.courseId" v-for="i in courses" :key="i.courseId">
              {{i.name}}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="上课班级" >
          <a-select
              placeholder="请选择班级"
              @focus="getClasses"
              v-model="selectClass"
              style="width: 210px"
              :allowClear="true"
          >
            <a-select-option :value="i.classId" v-for="i in classes" :key="i.classId">
              {{i.className}}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item>
          <div style="width: 250px;">
            <a-button type="primary" style="margin-right: 10px;" @click="onQueryCourseGroupInfo">
              查询
            </a-button>
            <a-button @click="onResetSearch">重置</a-button>
          </div>
        </a-form-item>
        <a-form-item label="开课时间">
          <a-select
              placeholder="请选择班级"
              v-model="selectCourseGroupTime"
              style="width: 200px"
              :allowClear="true"
          >
            <a-select-option :value="i" v-for="i in courseGroupTimes" :key="i">
              {{i}}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="上课老师">
          <a-select
              placeholder="请选择上课老师"
              @focus="getTeachers"
              style="width: 210px"
              :allowClear="true"
              v-model="selectTeacher"
          >
            <a-select-option :value="i.teacherId" v-for="i in teachers" :key="i.teacherId">
              {{i.teacherName}}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item>
          <div style="width: 250px;">
            <a-button type="primary" style="margin-right: 10px;" @click="onAdd">
              新建
            </a-button>
            <a-popconfirm
                title="是否批量删除选中的课程组信息?"
                @confirm="() => onMassDelete()"
                cancelText='取消'
                okText="确定"
                placement="bottom"
            >
              <a-icon slot="icon" type="question-circle-o" style="color: red"/>
              <a-button type="danger">删除</a-button>
            </a-popconfirm>
          </div>
        </a-form-item>
      </a-form>
    </div>

    <!--表格-->
    <div style="margin-top: 1em">
      <a-table
          :row-selection="rowSelection"
          :data-source="courseGroupData"
          :pagination="pagination"
      >
        <a-table-column title="所属课程" data-index="course" align="center" width="15%" :sorter="(a,b)=>a.course.localeCompare(b.course)"/>
        <a-table-column title="开课时间" data-index="courseGroupTime" align="center" width="15%"
                        :sorter="(a,b)=>{
                          let n=a.courseGroupTime.substr(0,4);
                          let n1=a.courseGroupTime.substr(5,1);
                          let m=b.courseGroupTime.substr(0,4);
                          let m1=b.courseGroupTime.substr(5,1);
                          if(n<m){
                            return -1;
                          }else if(n>m){
                            return 1;
                          }else{
                            if(n1=='二'&&m1=='一') return 1;
                            else return -1;
                          }
                          return 1;
                        }"/>
        <a-table-column title="上课老师" data-index="teachers" align="center" width="25%"/>
        <a-table-column title="上课班级" data-index="classes" align="center" width="25%"/>
        <a-table-column key="operation" title="操作" align="center" width="20%">
          <template slot-scope="text,record">
            <!-- 点击通过弹出的确认框-->
            <a-popconfirm
                v-if="courseGroupData.length"
                title="你确定要删除这个课程组信息吗?"
                @confirm="() => onDelete(record.key)"
                cancelText='取消'
                okText="确定"
                placement="bottom"
            >
              <a-icon slot="icon" type="question-circle-o" style="color: red"/>
              <a href="javascript:;" style="color: red">删除</a>
            </a-popconfirm>
            <span class="seize" style="margin-left: 1em"/>
            <a href="javascript:;" @click="onEdit(record.key)">编辑</a>

            <span class="seize" style="margin-left: 1em"/>
            <a href="javascript:;" @click="onCheck(record.key)">查看</a>
          </template>
        </a-table-column>
      </a-table>
      <!-- 点击查看弹出的对话框-->
      <a-modal title="查看课程组信息"
                :visible="checkVisible"
                :destroyOnClose="true"
                @ok="handleOk"
                @cancel="handleCancel">
        <div>
          <a-row :gutter="['24','24']">
            <a-col :span="12">
              课程组名：{{courseGroupDetailInfo.courseGroupName}}
            </a-col>
            <a-col :span="12">
              所属课程：{{courseGroupDetailInfo.simpleCourseGroupInfo.course}}
            </a-col>
          </a-row>
          <a-row :gutter="['24','24']">
            <a-col :span="12">
              开课时间：{{courseGroupDetailInfo.simpleCourseGroupInfo.courseGroupTime}}
            </a-col>
            <a-col :span="12">
              课程组长：{{courseGroupDetailInfo.courseGroupLeader.teacherNumber===null ? '':
                courseGroupDetailInfo.courseGroupLeader.teacherNumber+":"+courseGroupDetailInfo.courseGroupLeader.teacherName}}
            </a-col>
          </a-row>
          <div style="margin-top: 2em">上课老师：</div>
          <a-tag v-for="i in courseGroupDetailInfo.simpleCourseGroupInfo.teachers" :key="i.teacherId" style="margin-top: 1em">
            {{i.teacherNumber+":"+i.teacherName}}
          </a-tag>

          <div style="margin-top: 2em">上课班级：</div>
          <a-tag v-for="i in courseGroupDetailInfo.simpleCourseGroupInfo.classes" :key="i.classId" style="margin-top: 1em">
            {{i.className}}
          </a-tag>
        </div>
      </a-modal>

      <!-- 点击编辑弹出的对话框-->
      <a-modal title="编辑课程组信息"
               :visible="editVisible"
               :destroyOnClose="true"
               @ok="editCourseGroup"
               @cancel="onEditClose">
        <div>
          <a-row :gutter="['12','0']">
            <a-col :span="12">
              <a-form-item label="课程组名：">
                <a-input disabled v-model="courseGroupDetailInfo.courseGroupName"/>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="所属课程：">
                <a-select style="width: 100%"
                    v-model="courseGroupDetailInfo.simpleCourseGroupInfo.courseId"
                          :defaultValue="courseGroupDetailInfo.simpleCourseGroupInfo.course"
                          @focus="getCourses">
                  <a-select-option :value="i.courseId" v-for="i in courses" :key="i.courseId">
                    {{i.name}}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="['12','0']">
            <a-col :span="12">
              <a-form-item label="开课时间">
                <a-select
                    placeholder="请选择开课时间"
                    v-model="courseGroupDetailInfo.simpleCourseGroupInfo.courseGroupTime"
                    style="width: 100%"
                    :allowClear="true"
                >
                  <a-select-option :value="i" v-for="i in courseGroupTimes" :key="i">
                    {{i}}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="课程组长">
                <a-select
                    placeholder="请选择组长"
                    v-model="courseGroupDetailInfo.courseGroupLeader.teacherId"
                    style="width: 100%"
                >
                  <a-select-option :value="i.teacherId" v-for="i in courseGroupDetailInfo.simpleCourseGroupInfo.teachers" :key="i.teacherId">
                    {{i.teacherNumber+":"+i.teacherName}}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="['12','0']">
            <a-col :span="24">
              <a-form-item label="上课老师:">
                <a-select
                    mode="multiple"
                    v-model="courseGroupTeachers"
                    style="width: 100%"
                    placeholder="请选择上课老师"
                    @select="selectCourseGroupTeacher"
                    @deselect="deselectCourseGroupTeacher"
                    @focus="getTeachers"
                >
                  <a-select-option :value="i.teacherId" v-for="i in teachers" :key="i.teacherId">
                    {{i.teacherName}}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="['12','0']">
            <a-col :span="24">
              <a-form-item label="上课班级:">
                <a-select
                    mode="multiple"
                    v-model="courseGroupClasses"
                    style="width: 100%"
                    placeholder="请选择上课班级"
                    @select="selectCourseGroupClass"
                    @deselect="deselectCourseGroupClass"
                    @focus="getClasses"
                >
                  <a-select-option :value="i.classId" v-for="i in classes" :key="i.classId">
                    {{i.className}}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
        </div>
      </a-modal>

      <!--新建框-->
      <a-modal title="新建课程组信息" :visible="addVisible" :destroyOnClose="true"
               @ok="newCourseGroupInfo" @cancel="onAddClose">
        <div>
          <a-row :gutter="['12','0']">
<!--            <a-col :span="12">-->
<!--              <a-form-item label="课程组名：">-->
<!--                <a-input v-model="addCourseGroupInfo.courseGroupName"/>-->
<!--              </a-form-item>-->
<!--            </a-col>-->
            <a-col :span="12">
              <a-form-item label="所属课程：">
                <a-select style="width: 100%"
                          v-model="addCourseGroupInfo.courseId"
                          @focus="getCourses">
                  <a-select-option :value="i.courseId" v-for="i in courses" :key="i.courseId">
                    {{i.name}}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
<!--          </a-row>-->
<!--          <a-row :gutter="['12','0']">-->
            <a-col :span="12">
              <a-form-item label="开课时间">
                <a-select
                    placeholder="请选择开课时间"
                    v-model="addCourseGroupInfo.courseGroupTime"
                    style="width: 100%"
                >
                  <a-select-option :value="i" v-for="i in courseGroupTimes" :key="i">
                    {{i}}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="课程组长">
                <a-select
                    placeholder="请选择组长"
                    v-model="addCourseGroupInfo.courseGroupLeaderId"
                    style="width: 100%"
                    @focus="getTeachers"
                >
                  <a-select-option :value="i.teacherId" v-for="i in teachers" :key="i.teacherId">
                    {{i.teacherName}}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="['12','0']">
            <a-col :span="24">
              <a-form-item label="上课老师:">
                <a-select
                    mode="multiple"
                    v-model="addCourseGroupInfo.teacherIds"
                    style="width: 100%"
                    placeholder="请选择上课老师"
                    @focus="getTeachers"
                >
                  <a-select-option :value="i.teacherId" v-for="i in teachers" :key="i.teacherId">
                    {{i.teacherName}}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="['12','0']">
            <a-col :span="24">
              <a-form-item label="上课班级:">
                <a-select
                    mode="multiple"
                    v-model="addCourseGroupInfo.classIds"
                    style="width: 100%"
                    placeholder="请选择上课班级"
                    @focus="getClasses"
                >
                  <a-select-option :value="i.classId" v-for="i in classes" :key="i.classId">
                    {{i.className}}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
        </div>
      </a-modal>

    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import Cookie from "js-cookie";
export default {
  name: "ConGrolist",
  data() {
    return {
      form: this.$form.createForm(this, { name: 'courseGroup' }),
      //课程组开课时间
      courseGroupTime:'',
      //选择的课程
      selectCourse:undefined,
      //学院的所有课程
      courses:[],
      //选择的班级
      selectClass:undefined,
      //学院所有班级
      classes:[],
      //选择的老师
      selectTeacher:undefined,
      //选择的开课时间
      selectCourseGroupTime:undefined,
      //学院所有的开课时间
      courseGroupTimes:[
        '2017第一学期','2017第二学期',
          '2018第一学期','2018第二学期','2019第一学期','2019第二学期','2020第一学期','2020第二学期',
        '2021第一学期','2021第二学期','2022第一学期','2022第二学期',
      ],
      //学院所有老师
      teachers:[],
      //表格数据源
      courseGroupData:[],
      //分页
      pagination: {
        total: 0,
        showTotal: total => `共 ${total} 条`,
        pageSizeOptions: ['5', '6', '7', '8', '9', '10'],
        defaultPageSize: 5,
        showSizeChanger: true,
      }, // 配置分页配置
      selectedRowKeys: [],
      //查看框可见性
      checkVisible:false,
      editVisible:false,
      addVisible:false,
      //课程组详细信息
      courseGroupDetailInfo:{
        simpleCourseGroupInfo:{
          courseGroupId:'',
          courseGroupTime:'',
          course:'',
          teachers:[],
          classes:[]
        },
        courseGroupName:'',
        courseGroupLeader:''
      },
      courseGroupTeachers:[],
      courseGroupClasses:[],

      //新建的课程组详细信息
      addCourseGroupInfo:{
        collegeId:'',
        courseGroupName:'',
        courseId:'',
        courseGroupTime:'',
        classIds:[],
        teacherIds:[],
        courseGroupLeaderId:'',
      }
    }
  },
  beforeMount() {  //页面渲染完成时发起请求获取数据显示
    this.getCourseGroupList();
    console.log(Cookie.get("collegeId"))
    this.getCourses();
    this.getClasses();
    this.getTeachers();
  },
  methods: {
    getCourseGroupList(){
      this.$store.dispatch('courseGroup/courseGroupGetCouGro',{
        token:this.accessState.token,
        collegeId:this.accessState.collegeId
      }).then(()=>{
        this.courseGroupData=this.courseGroupState.courseGroupInfo
      }).catch(error=>{
        this.$message.error(error)
      })
    },
    //获取课程
    getCourses(){
      this.$store.dispatch('courseGroup/courseGroupGetCourses',{
        token:this.accessState.token,
        collegeId:this.accessState.collegeId
      }).then(()=>{
        this.courses=this.courseGroupState.courses
      }).catch(error=>{
        this.$message.error(error)
      })
    },
    //获取班级
    getClasses(){
      this.$store.dispatch('courseGroup/courseGroupGetClasses',{
        token:this.accessState.token,
        collegeId:this.accessState.collegeId
      }).then(()=>{
        this.classes=this.courseGroupState.classes
      }).catch(error=>{
        this.$message.error(error)
      })
    },
    //查询课程组信息
    onQueryCourseGroupInfo(){
      let result=this.courseGroupState.courseGroupInfo
      if(this.selectCourse!==''&&this.selectCourse!==undefined){
        result=result.filter(n=>{
          return n.courseId===this.selectCourse
        })
      }
      if(this.selectClass!==''&&this.selectClass!==undefined){
        result=result.filter(n=>{
          return n.classIds.indexOf(this.selectClass)!==-1
        })
      }
      if(this.selectCourseGroupTime!==''&&this.selectCourseGroupTime!==undefined){
        //console.log(this.selectCourseGroupTime)
        result=result.filter(n=>{
          return n.courseGroupTime===this.selectCourseGroupTime
        })
      }
      if(this.selectTeacher!==''&&this.selectTeacher!==undefined){
        result=result.filter(n=>{
          return n.teacherIds.indexOf(this.selectTeacher)!==-1
        })
      }
      this.courseGroupData=result
    },
    //重置搜索
    onResetSearch(){
      this.selectTeacher=undefined
      this.selectClass=undefined
      this.selectCourse=undefined
      this.selectCourseGroupTime=undefined
    },
    //获取学院所有老师
    getTeachers(){
      this.$store.dispatch('courseGroup/courseGroupGetTeacher',{
        token:this.accessState.token,
        collegeId:this.accessState.collegeId
      }).then(()=>{
        this.teachers=this.courseGroupState.teachers
      }).catch(error=>{
        this.$message.error(error)
      })
    },
    //新建课程组
    newCourseGroupInfo(){
      if(this.addCourseGroupInfo.courseGroupTime===''||this.addCourseGroupInfo.courseGroupTime===undefined
      ||this.addCourseGroupInfo.courseGroupLeaderId===''||this.addCourseGroupInfo.courseGroupLeaderId===undefined
      ||this.addCourseGroupInfo.courseId===''||this.addCourseGroupInfo.courseId===undefined){
        this.$message.info("请先完成必填项")
      }else{
        this.addCourseGroupInfo.collegeId=this.accessState.collegeId
        let courseName = '';
        console.log(this.addCourseGroupInfo.courseId)
        this.courses.forEach(item=>{
          if(item.courseId===this.addCourseGroupInfo.courseId)
            courseName = item.name;
        })
        this.addCourseGroupInfo.courseGroupName=courseName+'-'+this.addCourseGroupInfo.courseGroupTime
        this.$store.dispatch('courseGroup/courseGroupAdd', {
          token:this.accessState.token,
          addCourseGroupInfo:this.addCourseGroupInfo
        }).then(()=>{
          this.$message.info("新建成功")
          //再次发请求
          this.addVisible=false
          this.$store.dispatch('courseGroup/courseGroupGetCouGro',{
            token:this.accessState.token,
            collegeId:this.accessState.collegeId
          }).then(()=>{
            this.courseGroupData=this.courseGroupState.courseGroupInfo
            this.addCourseGroupInfo={
              courseGroupName:'', courseId:'', courseGroupTime:'', classIds:[], teacherIds:[], courseGroupLeaderId:'',
            }
          }).catch(error=>{
            this.$message.error(error)
          })

        }).catch(error=>{
          this.$message.error(error)
        })
      }

    },
    //编辑课程组
    editCourseGroup(){
      // this.$store.dispatch('courseGroup/courseGroupListModify',{
      //   token:this.accessState.token,
      //   editCourseGroupInfo:{
      //     courseGroupId:this.courseGroupDetailInfo.simpleCourseGroupInfo.courseGroupId,
      //     courseGroupTime:this.courseGroupDetailInfo.simpleCourseGroupInfo.courseGroupTime,
      //     courseId:this.courseGroupDetailInfo.simpleCourseGroupInfo.courseId,
      //     courseGroupName:this.courseGroupDetailInfo.courseGroupName+'-'+this.courseGroupDetailInfo.simpleCourseGroupInfo.courseGroupTime,
      //     courseGroupLeader:this.courseGroupDetailInfo.courseGroupLeader.teacherId
      //   }
      // }).then(()=>{
      //   this.$message.info("更新成功")
      //   this.editVisible=false
      //
      //   this.$store.dispatch('courseGroup/courseGroupGetCouGro',{
      //     token:this.accessState.token,
      //     collegeId:this.accessState.collegeId
      //   }).then(()=>{
      //     this.courseGroupData=this.courseGroupState.courseGroupInfo
      //   }).catch(error=>{
      //     this.$message.error(error)
      //   })
      //
      // }).catch(error=>{
      //   this.$message.error(error)
      // })

      this.$store.dispatch('courseGroup/courseGroupGetCouGro',{
        token:this.accessState.token,
        collegeId:this.accessState.collegeId
      }).then(()=>{
        this.courseGroupData=this.courseGroupState.courseGroupInfo
        this.editVisible=false
      }).catch(()=>{
        this.$message.error("更新信息失败")
      })
    },
    //批量删除
    onMassDelete(){
      this.$store.dispatch('courseGroup/BatchDelete', {
        token:this.accessState.token,
        courseGroupIds:this.selectedRowKeys
      }).then(()=>{
        this.$message.info("操作成功")
        this.$store.commit("courseGroup/MASS_DELETE_COURSE_GROUP",this.selectedRowKeys)
        this.courseGroupData=this.courseGroupState.courseGroupInfo
      }).catch(error=>{
        this.$message.error(error)
      })
    },
    //删除某个课程组
    onDelete(key){
      this.$store.dispatch('courseGroup/courseGroupDelete', {
        token:this.accessState.token,
        courseGroupId:key
      }).then(()=>{
        this.$message.info("操作成功")
        this.$store.commit("courseGroup/DELETE_COURSE_GROUP",key)
        this.courseGroupData=this.courseGroupState.courseGroupInfo
      }).catch(error=>{
        this.$message.error(error)
      })
    },
    //查看某个课程组
    onCheck(key){
      this.$store.dispatch('courseGroup/detailCourseIGroupInfo', {
        token:this.accessState.token,
        courseGroupId:key
      }).then(()=>{
        this.courseGroupDetailInfo=this.courseGroupState.courseGroupDetailInfo
        this.checkVisible=true
        //console.log(this.courseGroupDetailInfo.simpleCourseGroupInfo.teachers)
        //console.log(this.courseGroupDetailInfo.simpleCourseGroupInfo.classes)
      }).catch(error=>{
        this.$message.error(error)
      })
    },
    //编辑框
    onEdit(key){
      this.$store.dispatch('courseGroup/detailCourseIGroupInfo', {
        token:this.accessState.token,
        courseGroupId:key
      }).then(()=>{
        this.courseGroupDetailInfo=this.courseGroupState.courseGroupDetailInfo
        let teachers=[]
        let classes=[]
        for(let i of this.courseGroupDetailInfo.simpleCourseGroupInfo.teachers){
          teachers.push(i.teacherId)
        }
        for(let i of this.courseGroupDetailInfo.simpleCourseGroupInfo.classes){
          classes.push(i.classId)
        }
        this.courseGroupClasses=classes
        this.courseGroupTeachers=teachers
        this.editVisible=true
      }).catch(error=>{
        this.$message.error(error)
      })
    },
    onEditClose(){
      this.editVisible=false
      this.$store.dispatch('courseGroup/courseGroupGetCouGro',{
        token:this.accessState.token,
        collegeId:this.accessState.collegeId
      }).then(()=>{
        this.courseGroupData=this.courseGroupState.courseGroupInfo
      }).catch(error=>{
        this.$message.error(error)
      })
    },
    //添加课程组
    onAdd(){
      this.addVisible=true
    },
    onAddClose(){
      this.addVisible=false
      this.addCourseGroupInfo={
        courseGroupName:'', courseId:'', courseGroupTime:'', classIds:[], teacherIds:[], courseGroupLeaderId:'',
      }
    },
    //弹出的确定取消按钮
    handleOk(){
      this.checkVisible=false
    },
    handleCancel(){
      this.checkVisible=false
    },
    //将老师添加进课程组
    selectCourseGroupTeacher(teacherId){
      //console.log(teacherId)
      this.$store.dispatch('courseGroup/selectCourseGroupTeacher',{
        token:this.accessState.token,
        courseGroupId:this.courseGroupDetailInfo.simpleCourseGroupInfo.courseGroupId,
        teacherId:teacherId
      }).then(()=>{
        //再次发请求
        this.$store.dispatch('courseGroup/detailCourseIGroupInfo', {
          token:this.accessState.token,
          courseGroupId:this.courseGroupDetailInfo.simpleCourseGroupInfo.courseGroupId,
        }).then(()=>{
          this.courseGroupDetailInfo=this.courseGroupState.courseGroupDetailInfo
        }).catch(error=>{
          this.$message.error(error)
        })


      }).catch(error=>{
        this.$message.error(error)
      })
    },
    //将老师从课程组中删除
    deselectCourseGroupTeacher(teacherId){
      //console.log(teacherId)
      this.$store.dispatch('courseGroup/deselectCourseGroupTeacher',{
        token:this.accessState.token,
        courseGroupId:this.courseGroupDetailInfo.simpleCourseGroupInfo.courseGroupId,
        teacherId:teacherId
      }).then(()=>{

        //再次发请求
        this.$store.dispatch('courseGroup/detailCourseIGroupInfo', {
          token:this.accessState.token,
          courseGroupId:this.courseGroupDetailInfo.simpleCourseGroupInfo.courseGroupId,
        }).then(()=>{
          this.courseGroupDetailInfo=this.courseGroupState.courseGroupDetailInfo
        }).catch(error=>{
          this.$message.error(error)
        })

      }).catch(error=>{
        this.$message.error(error)
      })
    },

    //将班级从课程组中删除
    deselectCourseGroupClass(classId){
      //console.log(classId)
      this.$store.dispatch('courseGroup/deselectCourseGroupClass',{
        token:this.accessState.token,
        courseGroupId:this.courseGroupDetailInfo.simpleCourseGroupInfo.courseGroupId,
        classId:classId
      }).then(()=>{
        this.$message.info("删除成功")
      }).catch(error=>{
        this.$message.error(error)
      })
    },
    //将班级添加进课程组
    selectCourseGroupClass(classId){
      //console.log(teacherId)
      this.$store.dispatch('courseGroup/selectCourseGroupClass',{
        token:this.accessState.token,
        courseGroupId:this.courseGroupDetailInfo.simpleCourseGroupInfo.courseGroupId,
        classId:classId
      }).then(()=>{
        this.$message.info("添加成功")
      }).catch(error=>{
        this.$message.error(error)
      })
    },

  },

  computed:{
    ...mapState({ // 这个是提取store中access文件夹目录下的数据
      'accessState': 'access',
      'courseGroupState':'courseGroup'
    }),
    rowSelection(){
      return {
        selectedRowKeys: this.selectedRowKeys,
        onChange: selectedRowKeys=>{
          this.selectedRowKeys = selectedRowKeys;
        }
      }
    }
  }
}
</script>

<style scoped>

</style>
